#include <stdio.h>
#include <stdlib.h>

#define A_HUNDRED_MB 1024*1024*100

void pressEnter();

int main()
{
    size_t mem_size = 0;
    char *p1;
start_malloc:
    p1 = (char*)malloc(A_HUNDRED_MB);
    if(!p1)
    {
        printf("没有足够的内存！\n");
        goto exit;
    }
    mem_size++;
    printf("当前已分配%lu00MB内存\n", mem_size);
    memset(p1, 0, A_HUNDRED_MB);
    p1 = (char*)NULL;
    printf("按回车键继续分配内存\n");
    pressEnter();
    goto start_malloc;
exit:
    printf("按回车键退出\n");
    pressEnter();
    return 0;
}

void pressEnter()
{
    scanf("*");
    getchar();
    return;
}
